package com.dameng.jianyouquan.interviewer.activity;

import android.content.Intent;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.dameng.jianyouquan.R;
import com.wildma.idcardcamera.camera.IDCardCamera;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class AuthenricationPersionActivity extends AppCompatActivity {

    @BindView(R.id.iv_idcard_front)
    ImageView ivIdcardFront;
    @BindView(R.id.rl_idcard_front)
    RelativeLayout rlIdcardFront;
    @BindView(R.id.iv_idcard_back)
    ImageView ivIdcardBack;
    @BindView(R.id.rl_idcard_back)
    RelativeLayout rlIdcardBack;
    @BindView(R.id.tv_next_step)
    TextView tvNextStep;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_authenrication_persion);
        ButterKnife.bind(this);

    }


    @OnClick({R.id.rl_idcard_front, R.id.rl_idcard_back, R.id.tv_next_step})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.rl_idcard_front:
                IDCardCamera.create(this).openCamera(IDCardCamera.TYPE_IDCARD_FRONT);
                break;
            case R.id.rl_idcard_back:
                IDCardCamera.create(this).openCamera(IDCardCamera.TYPE_IDCARD_BACK);
                break;
            case R.id.tv_next_step:
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == IDCardCamera.RESULT_CODE) {
            //获取图片路径，显示图片
            final String path = IDCardCamera.getImagePath(data);
            if (!TextUtils.isEmpty(path)) {
                if (requestCode == IDCardCamera.TYPE_IDCARD_FRONT) { //身份证正面
                    ivIdcardFront.setImageBitmap(BitmapFactory.decodeFile(path));
                } else if (requestCode == IDCardCamera.TYPE_IDCARD_BACK) {  //身份证反面
                    ivIdcardBack.setImageBitmap(BitmapFactory.decodeFile(path));
                }
                //实际开发中将图片上传到服务器成功后需要删除全部缓存图片
//                FileUtils.clearCache(this);
            }
        }
    }
}
